<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>


    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Connection Manager POST Transaction</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="../../build/event/event-min.js"></script>
<script type="text/javascript" src="../../build/connection/connection-min.js"></script>


<!--begin custom header content for this example-->
<style>
#container li {margin-left:2em;}
</style>


<!--end custom header content for this example-->

</head>

<body class="yui-skin-sam">


<h1>Connection Manager POST Transaction</h1>

<div class="exampleIntro">
	<p>To create a POST transaction using <a href="http://developer.yahoo.com/yui/connection/">Connection Manager</a>, you will need to construct a data string as the POST message. The following code example provides a step-by-step approach to creating a simple POST transaction.</p>

<p>Click "Send a POST Request" below to try it out, then read the description below to learn how to send POST data to the server using Connection Manager.</p>			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<div id="container"></div>

<script>
var div = document.getElementById('container');

var handleSuccess = function(o){
	YAHOO.log("The success handler was called.  tId: " + o.tId + ".", "info", "example");
	if(o.responseText !== undefined){
		div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
		div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
		div.innerHTML += "<li>HTTP headers received: <ul>" + o.getAllResponseHeaders + "</ul></li>";
		div.innerHTML += "<li>PHP response: " + o.responseText + "</li>";
		div.innerHTML += "<li>Argument object: Array ([0] => " + o.argument[0] +
						 " [1] => " + o.argument[1] + " )</li>";
	}
};

var handleFailure = function(o){
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");

	if(o.responseText !== undefined){
		div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
		div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
	}
};

var callback =
{
  success:handleSuccess,
  failure:handleFailure,
  argument:['foo','bar']
};

var sUrl = "assets/post.php";
var postData = "username=anonymous&userid=0";

function makeRequest(){

	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
	
	YAHOO.log("Initiating request; tId: " + request.tId + ".", "info", "example");

}

YAHOO.log("As you interact with this example, relevant steps in the process will be logged here.", "info", "example");
</script>
<form><input type="button" value="Send a POST Request" onClick="makeRequest();"></form>
<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
